import qs from "qs";

export function updateUserRoles(user) {
    return new Promise(resolve => {
        axios.post('/user/updateUserRoles', user, {
            headers: {
                'content-type': 'application/json' //@requestBody,不能用qs
            }
        }).then(resp => {
            resolve(resp.data);
        }).catch(() => resolve({code: 204, message: '服务器连接失败'}));
    });
}

export function getUsers(form) {
    return new Promise(resolve => {
        axios.post("/user/getUsers", qs.stringify({
            pageNo: form.pageNo,
            pageSize: form.pageSize
        })).then((resp) => {
            resolve(resp.data);
        }).catch(() => {
            resolve({code: 204, message: '服务器连接失败'})
        });
    });
}

export function login(form) {
    return new Promise(resolve => {
        axios.post('/user/login', qs.stringify({
            username: form.name,
            password: form.passWord
        })).then(resp => {
            resolve(resp.data);
        }).catch(() => {
            //原来在main.js 中没有return rs 也是归于这一类
            resolve({code: 204, message: '服务器连接失败'})
        });
    });

}


export function getUserCount() {
    return new Promise(resolve => {
        axios.post("/user/getUserCount").then(rs => {
            resolve(rs.data);
        })
    })
}